package com.grpc;


/**
 * create by yongli on 2022-01-06 15:14
 */

public class HelloWorldServer {
//
//    private static final Logger logger = LoggerFactory.getLogger(HelloWorldServer.class.getName());
//
//    private Server server;
//
//    private void start() throws IOException {
//        int port = 50051;
//        server = NettyServerBuilder.forPort(port)
//                .addService(new GreeterImpl())
//                .build()
//                .start();
//        logger.info("Server started, listening on " + port);
//        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
//            System.err.println("*** shutting down gRPC server since JVM is shutting down");
//            HelloWorldServer.this.stop();
//            System.err.println("*** server shut down");
//        }));
//    }
//
//    private void stop() {
//        if (server != null) {
//            server.shutdown();
//        }
//    }
//
//    private void blockUntilShutdown() throws InterruptedException {
//        if (server != null) {
//            server.awaitTermination();
//        }
//    }
//
//    public static void main(String[] args) throws IOException, InterruptedException {
//        final HelloWorldServer server = new HelloWorldServer();
//        server.start();
//        server.blockUntilShutdown();
//    }
//
//    // GreeterGrpc类，及其内部类
//    static class GreeterImpl extends GreeterGrpc.GreeterImplBase {
//
//        @Override
//        public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
//            String name = req.getName();
//            logger.info( "Received name: " + name);
//            HelloReply reply = HelloReply.newBuilder().setMessage("Hello,你找到服务器了" + name).build();
//            responseObserver.onNext(reply);
//            responseObserver.onCompleted();
//        }
//    }
}
